// import CompConst from "../compConst";
import _ from 'lodash';
window._ = _;
export default {

}

export let MixinsFill = {
    data() {
        return {
            mixinsFillOpts: _.get(this, 'options', _.get(this, 'widget.options', _.get(this, 'element.options', {}))),
            screenHeight: null,
            offset: null,
        }
    },
    mounted() {
        // debugger;
        if (!this.isDevEnv && _.get(this.mixinsFillOpts, 'fillMode', 'custom') === "auto" && window.isPC()) {
            $(window).resize(() => {
                this.screenHeight = $(window).height();
            });
        }
        this.$nextTick(()=>{
         
            this.setStyleOptions(this.styleCss)
        })
    },
    watch: {
        widgetInstance(val) {
            // debugger;
            if (!this.isDevEnv && _.get(this.mixinsFillOpts, 'fillMode', 'custom') === "auto") {
                this.screenHeight = $(window).height();
                this.offset = $(val.element()).offset();
            }
        },
        styleCss(val){
            this.setStyleOptions(val)
            
        }
    },
    methods: {
        setStyleOptions(val){
            if(!val||!this.$el.querySelectorAll)return
            //if(this._props.widget&&this._props.widget.StyleDesignerOption&&this._props.widget.StyleDesignerOption.indexOf("font")!=-1){
                let input = this.$el.querySelectorAll("input")
                let textArea = this.$el.querySelectorAll("textarea")
                let realStyle = val.split(';')
                realStyle= realStyle.filter(i=>{
                   return i.indexOf("font")!=-1||i.indexOf('color')!=-1||i.indexOf('text')!=-1||i.indexOf("letter")!=-1||i.indexOf("line")!=-1
                })
            
                realStyle=realStyle.join(";")
                if(input){
                    input.forEach(ele=>{
                        ele.setAttribute("style",realStyle)
                    })
                    
                }
                if(textArea){
                    textArea.forEach(ele=>{
                        ele.setAttribute("style",realStyle)
                    })
                }
           // }
          
            // if(this._op)
     
        },
        mixinsSetHeight() {
            this.$nextTick(() => {this.mixinsInitOffset($(this.$el).offset());});
        },
        mixinsInitOffset(offset) {
            if (!this.isDevEnv && _.get(this.mixinsFillOpts, 'fillMode', 'custom') === "auto") {
                this.screenHeight = $(window).height();
                this.offset = offset;
            }
        },
        //表达式解析器
        mixinsConvertExp(farr,) {
            farr.forEach((f, i) => {
              if (!f){
                  return;
              } 
              try {
                f=JSON.parse(f)
              } catch (error) {
                
              }
              let cv = f.value || f;
              
          
              if (typeof cv == "string" && cv.includes("@")) {
            
                let ccv = Funcs.AtVarTransform(cv);
                  if(typeof ccv =='object'){
                    ccv = Object.keys(ccv).map(k=>{
                      // return `'${ccv[k]}'`
                      return ccv[k]
                    }).filter(ccvf=>ccvf)
                    .join()
            
                    farr[1] = farr[1]=='='?'in':(farr[1]=='<>'?"notin":farr[1])
                  }
                  farr[i] = ccv; 
                
              } else if (f && f.push) {
                convertExp(f);
              }
            });
          }
    },
    computed: {
        computedHeight() {
            // debugger;
            if (_.isNil(this.mixinsFillOpts.fillMode) || this.mixinsFillOpts.fillMode === 'none') { return null; }
            if (_.get(this.mixinsFillOpts, 'fillMode', 'custom') === "auto") {
                if (this.offset) {
                    let defMarginBottom = this.mixinsFillOpts.showPager ? 66 : 0;
                    let fillMarginBottom = +_.get(this.mixinsFillOpts, "fillMarginBottom", 0);
                    if (_.isNaN(fillMarginBottom)) {
                        fillMarginBottom = 0;
                    }
                    let offsetComputedHeight = _.get(this,'confOffsetHeight',30);
                    return this.screenHeight - this.offset.top - fillMarginBottom - defMarginBottom - (offsetComputedHeight);
                } else {
                    return 500;
                }
            }
            return this.mixinsFillOpts.height || 500;
        },
    }
}